<?php
echo "<html xmlns='http://www.w3.org/1999/xhtml'>";
echo "<head>";

echo "<title>BASAX</title>";
echo "<link rel='shortcut icon' href='images/icone.ico' type='image/x-icon'/>";
echo "<link rel='stylesheet' media='screen' type='text/css' title='DesignInterface' href='interface.css' />";
echo "<link rel='icon' href='icone.ico' type='image/x-icon'/>";

echo "</head>";
echo "<body>";

echo "<DIV id='container'>";
echo "<ul id='menu'>";
echo "	<li>";
echo "		<a href='index.php' class='current' title='saisie'>Saisie</a>";
echo "	</li>";
echo "	<li>";
echo "		<a href='consultation.php' class='ghost' title='consultation'>Consultation</a>";
echo "	</li>";
echo "	<li>";
echo "<hr />";

echo "<DIV class='on content'>";

echo "<DIV class='on content' style='margin-top:380px; width:100px;height:300px;position:relative;float:left;background-image: url(images/silhouette.jpg); background-repeat:no-repeat;'>";
// echo "<DIV class='on content' style='width:100px;height:680px;position:relative;float:left;background-color:white;'>";
echo "</DIV>";

$link = mysql_connect ( 'localhost', 'userbasespatax', 'tyujhg' ) or die ( 'Impossible de se connecter : ' . mysql_error () );
mysql_select_db ( 'BaseSpatax' ) or die ( 'Impossible de s�lectionner la base de donn�es' );

echo "<div class='on content' id='1' style='position:relative; float:left; display:block; width:1000px; height:680px;'>";

if (isset ( $_GET ['submit'] )) {
	$submit = $_GET ['submit'];
} else {
	$submit = "";
}

if ($submit == "yes") {
	
	if (isset ( $_POST ['famille'] ) and isset ( $_POST ['individu'] ) and $_POST ['famille'] != '' and $_POST ['individu'] != '') {
		
		$famille = $_POST ['famille'];
		$individu = $_POST ['individu'];
		
		foreach ( $_FILES as $file ) {
			if (isset ( $file ['name'] ) and $file ['error'] == 0) {
				$infosfichier = pathinfo ( $file ['name'] );
				$extension_upload = $infosfichier ['extension'];
				move_uploaded_file ( $file ['tmp_name'], 'uploads/' . basename ( $file ['name'] ) );
				$nomfichier = $file ['name'];
			}
		}
		
		if (isset ( $_POST ['diagnostique'] )) {
			$diagnostique = $_POST ['diagnostique'];
		} else {
			$diagnostique = "";
		}
		
		if (isset ( $_POST ['validation'] )) {
			$validation = $_POST ['validation'];
		} else {
			$validation = "";
		}
		
		if (isset ( $_POST ['afaire'] )) {
			$afaire = $_POST ['afaire'];
		} else {
			$afaire = "";
		}
		
		if (isset ( $_POST ['commentairesconclusion'] )) {
			$commentairesconclusion = $_POST ['commentairesconclusion'];
		} else {
			$commentairesconclusion = "";
		}
		
		if (isset ( $_POST ['locusteste'] )) {
			$locusteste = $_POST ['locusteste'];
		} else {
			$locusteste = "";
		}
		
		if (isset ( $_POST ['modelinkage'] )) {
			$modelinkage = $_POST ['modelinkage'];
		} else {
			$modelinkage = "";
		}
		
		if (isset ( $_POST ['haplotype'] )) {
			$haplotype = $_POST ['haplotype'];
		} else {
			$haplotype = "";
		}
		
		if (isset ( $_POST ['linkage'] )) {
			$linkage = $_POST ['linkage'];
		} else {
			$linkage = "";
		}
		
		if (isset ( $_POST ['datelinkage'] )) {
			$datelinkage = $_POST ['datelinkage'];
		} else {
			$datelinkage = "";
		}
		
		if (isset ( $_FILES ['fichierattachelinkage'] ['name'] )) {
			$fichierattachelinkage = $_FILES ['fichierattachelinkage'] ['name'];
		} else {
			$fichierattachelinkage = "";
		}
		
		if (isset ( $_POST ['commentairelinkage'] )) {
			$commentairelinkage = $_POST ['commentairelinkage'];
		} else {
			$commentairelinkage = "";
		}
		
		$recupereindexmaxlinkage = "SELECT MAX(`index`) FROM `linkage`";
		$resultindex = mysql_query ( $recupereindexmaxlinkage ) or die ( "Impossible de r�cup�rer l'index de la table linkage" );
		while ( $ligne = mysql_fetch_row ( $resultindex ) ) {
			$indexlinkage = $ligne [0] + 1;
		}
		$insertlinkage = "INSERT INTO `BaseSpatax`.`linkage` (
		`index`, `codefamille`, `codeind`, `mode`, `locusteste`, `haplotype`, `linkage`, `commentlinkage`, `date`, `fichierattache`, `diagnostic`, `afaire`, `validation`, `commentairesconclusion`) 
		VALUES (
		'$indexlinkage', '$famille', '$individu', '$modelinkage', '$locusteste', '$haplotype', '$linkage', '$commentairelinkage', '$datelinkage', '$fichierattachelinkage', '$diagnostique', '$afaire', '$validation', '$commentairesconclusion');";
		mysql_query ( $insertlinkage ) or die ( "Impossible d'ins�rer donn�es dans table linkage : " . mysql_error () );
		
		if (isset ( $_POST ['gene'] )) {
			$gene = $_POST ['gene'];
		} else {
			$gene = "";
		}
		
		if (isset ( $_POST ['techniquescreening'] )) {
			$techniquescreening = $_POST ['techniquescreening'];
		} else {
			$techniquescreening = "";
		}
		
		if (isset ( $_POST ['modescreening'] )) {
			$modescreening = $_POST ['modescreening'];
		} else {
			$modescreening = "";
		}
		
		if (isset ( $_POST ['mutation1'] )) {
			$mutation1 = $_POST ['mutation1'];
		} else {
			$mutation1 = "";
		}
		
		if (isset ( $_POST ['mutation2'] )) {
			$mutation2 = $_POST ['mutation2'];
		} else {
			$mutation2 = "";
		}
		
		if (isset ( $_POST ['cosegregation'] )) {
			$cosegregation = $_POST ['cosegregation'];
		} else {
			$cosegregation = "";
		}
		
		if (isset ( $_POST ['datescreening'] )) {
			$datescreening = $_POST ['datescreening'];
		} else {
			$datescreening = "";
		}
		
		if (isset ( $_POST ['polymorphismes'] )) {
			$polymorphismes = $_POST ['polymorphismes'];
		} else {
			$polymorphismes = "";
		}
		
		if (isset ( $_FILES ['fichierattachescreening'] ['name'] )) {
			$fichierattachescreening = $_FILES ['fichierattachescreening'] ['name'];
		} else {
			$fichierattachescreening = "";
		}
		
		$recupereindexmaxscreening = "SELECT MAX(`index`) FROM `screening`";
		$resultindex = mysql_query ( $recupereindexmaxscreening ) or die ( "Impossible de r�cup�rer l'index de la table screening" );
		while ( $ligne = mysql_fetch_row ( $resultindex ) ) {
			$indexscreening = $ligne [0] + 1;
		}
		$insertlinkage = "INSERT INTO `BaseSpatax`.`screening` (
		`index`, `codefamille`, `codeind`,`gene`, `technique`, `commentairessequencage`, `commentairespuceshautedensite`, `date`, `mode`, `mutation1`, `mutation2`, `cosegregation`, `polymorphismes`,`fichierattache`, `diagnostic`, `afaire`, `validation`, `commentairesconclusion`) 
		VALUES (
		'$indexscreening', '$famille', '$individu','$gene', '$techniquescreening', '', '', '$datescreening', '$modescreening', '$mutation1', '$mutation2', '$cosegregation', '$polymorphismes', '$fichierattachelinkage', '$diagnostique', '$afaire', '$validation', '$commentairesconclusion');";
		mysql_query ( $insertlinkage ) or die ( "Impossible d'ins�rer donn�es dans table screening : " . mysql_error () );
		
		if (isset ( $_POST ['techniqueanalysis'] )) {
			$techniqueanalysis = $_POST ['techniqueanalysis'];
		} else {
			$techniqueanalysis = "";
		}
		
		if (isset ( $_FILES ['fichierattacheanalysis'] ['name'] )) {
			$fichierattacheanalysis = $_FILES ['fichierattacheanalysis'] ['name'];
		} else {
			$fichierattacheanalysis = "";
		}
		
		if (isset ( $_POST ['variants'] )) {
			$variants = $_POST ['variants'];
		} else {
			$variants = "";
		}
		
		$recupereindexmaxwga = "SELECT MAX(`index`) FROM `wholegenomeanalysis`";
		$resultindex = mysql_query ( $recupereindexmaxwga ) or die ( "Impossible de r�cup�rer l'index de la table wholegenomeanalysis" );
		while ( $ligne = mysql_fetch_row ( $resultindex ) ) {
			$indexwga = $ligne [0] + 1;
		}
		$insertlinkage = "INSERT INTO `BaseSpatax`.`wholegenomeanalysis` (
		`index`, `codefamille`, `codeind`,`technique`, `variants` ,`fichierattache`, `diagnostic`, `afaire`, `validation`, `commentairesconclusion`) 
		VALUES (
		'$indexwga', '$famille', '$individu','$techniqueanalysis', '$variants', '$fichierattacheanalysis', '$diagnostique', '$afaire', '$validation', '$commentairesconclusion');";
		mysql_query ( $insertlinkage ) or die ( "Impossible d'ins�rer donn�es dans table screening : " . mysql_error () );
	} else {
		echo "<FONT color=red> Vous devez indiquer la famille et l'individu <FONT><br>";
	}
} else {
	
	echo "<FORM ACTION='index.php?submit=yes' METHOD='POST' ENCTYPE='multipart/FORM-data'>";
	// echo "<TABLE cellspacing='10' style='position:relative; float:left; margin-top:30px; display:block; overflow:auto; cols=5;'>";
	
	// echo "<div class='on content' style='position:relative; float:left; display:block;'>";
	
	echo "<div class='on content' id='linkage' style='position:relative; float:left; visibility:hidden;></TD></TR>";
	echo "<TR><TD>Famille : </TD><TD><input type='textarea' style='width:100px;' name='famille' value=''><FONT color=red>*</font></TD>";
	echo "<TR><TD>Individu : </TD><TD><input type='textarea' style='width:100px;' name='individu' value=''><FONT color=red>*</font></TD>";
	
	echo "<TR><TD><H1>Linkage</H1></TD></TR>";
	echo "<TR><TD>Locus test� : </TD><TD><input type='textarea' style='width:100px;' name='locusteste' value=''></TD></TR>";
	echo "<TR><TD>Mode : </TD><TD><SELECT name='modelinkage' size='1'>
			<OPTION></OPTION>
			<OPTION>recessif</OPTION>
			<OPTION>dominant</OPTION>
			<OPTION>li� � l'X</OPTION>
		</SELECT></TD>";
	echo "<TD>Haplotype : </TD><TD><SELECT name='haplotype' size='1'>
			<OPTION></OPTION>
			<OPTION>pas geno id</OPTION>
			<OPTION>geno id sans homozygotie</OPTION>
			<OPTION>homozygotie</OPTION>
			<OPTION>cosegr�gation</OPTION>
			<OPTION>pas de cosegr�gation</OPTION>
			<OPTION>homozygotie</OPTION>
		</SELECT></TD>";
	echo "</TR>";
	echo "<TR><TD>Linkage : </TD><TD><SELECT name='linkage' size='1'>
			<OPTION></OPTION>
			<OPTION>exclusion
			<OPTION>liaison significative
			<OPTION>autre
		</SELECT></TD>";
	echo "<TR><TD>Date : </TD><TD><input type='textarea' style='width:100px;' name='datelinkage' value=''></TD>";
	echo "<TD>Attacher un fichier : </TD><TD>";
	echo "<INPUT type='file' name='fichierattachelinkage'/>";
	echo "</TD></TR>";
	echo "<TD>Commentaires : </TD><TD><TEXTAREA NAME='commentairelinkage' COLS=20 ROWS=1></TEXTAREA></TD></TR>";
	echo "<BR>";
	
	echo "</div>";
	
	echo "<TR><TD><H1>screening g�ne</H1></TD></TR>";
	echo "<TR><TD>G�ne : </TD><TD><input type='textarea' style='width:100px;' name='gene' value=''></TD>";
	echo "<TD>Mode : </TD><TD><SELECT name='modescreening' size='1'>
			<OPTION></OPTION>
			<OPTION>recessif</OPTION>
			<OPTION>dominant</OPTION>
			<OPTION>li� � l'X</OPTION>
		</SELECT></TD>";
	echo "<TR><TD>Technique : </TD><TD><SELECT name='techniquescreening' size='1'>
			<OPTION></OPTION>
			<OPTION>MLPA</OPTION>
			<OPTION>sequen�age</OPTION>
			<OPTION>DHPLC</OPTION>
			<OPTION>HRM</OPTION>
			<OPTION>puces haute densit�</OPTION>
		</SELECT></TD>";
	echo "<TD>Mutation1 : </TD><TD><input type='textarea' style='width:100px;' name='mutation1' value=''></TD>";
	echo "<TD>Mutation2 : </TD><TD><input type='textarea' style='width:100px;' name='mutation2' value=''></TD>";
	echo "</TR>";
	echo "<TR><TD>Date : </TD><TD><input type='textarea' style='width:100px;' name='datescreening' value=''></TD>";
	echo "<TD>Cosegr�gation : </TD><TD><input type='textarea' style='width:100px;' name='cosegregation' value=''></TD></TR>";
	echo "<TD>Polymorphismes : </TD><TD><TEXTAREA NAME='polymorphismes' COLS=20 ROWS=1></TEXTAREA></TD></TR>";
	echo "<BR>";
	echo "<TR><TD><H1>Whole Genome Analysis</H1></TD></TR>";
	echo "<TR><TD>Technique : </TD><TD><SELECT name='techniqueanalysis' size='1'>
			<OPTION></OPTION>
			<OPTION>Puces moyenne/haute densit�</OPTION>
			<OPTION>puces linkage</OPTION>
			<OPTION>exome</OPTION>
		</SELECT></TD>";
	echo "<TD>Attacher un fichier : </TD><TD>";
	echo "<INPUT type='file' name='fichierattachescreening'/>";
	echo "</TD></TR>";
	echo "<TR><TD>Variants : </TD><TD><input type='textarea' style='width:100px;' name='variants' value=''></TD></TR>";
	
	// echo "</TABLE>";
	echo "</div>";
	
	echo "<hr align='center' width='50%' color='midnightblue' size='3'>  ";
	// echo "</div>";
	
	echo "<div class='on content' id='2' style='position:relative; float:left; display:block; width:137px; height:680px; background-color:#A5CADC; color:'white';>";
	
	echo "<FONT COLOR=white>";
	echo "<p>Diagnostique : <input type='textarea' style='width:130px;' name='diagnostique' value=''></P>";
	echo "<P><BR>Validation : 	";
	echo "<DD><label><input type='checkbox' name='validation' value='oui'> oui </label><br>";
	echo "<DD><input type='checkbox' name='validation' value='non'> non </label><br></P>";
	echo "<P><BR>A faire : <TEXTAREA NAME='afaire' COLS=15 ROWS=3></TEXTAREA></P>";
	
	echo "<P><BR>Commentaires : <TEXTAREA NAME='commentairesconclusion' COLS=15 ROWS=3></TEXTAREA></P>";
	
	echo "<FONT>";
	
	echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><input type='submit' value=' Envoyer '><br><br>";
	
	echo "</div>";
	
	echo "</DIV>";
	
	echo "</FORM>";
}

// Fermeture de la connexion
mysql_close ( $link );

// echo "<p align='center'><a href='http://www.sph.umich.edu/csg/abecasis/Merlin/tour/linkage.html' title='Tutoriel Merlin'>Tutoriel Merlin</a> | <a href='http://www.sph.umich.edu/csg/abecasis/PedStats/tour/' title='tutoriel Pedstats'>Tutoriel Pedstats</a></p>";
echo "</DIV>";

echo "</body>";
echo "</html>";
